package com.uenpay.im.ui.old.activity.transfer;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * 
 */
public class GetTransferDetailInvokItem extends HttpInvokeItem {

	public class GetTransferDetailInvokItemResult extends HttpInvokeResult {
		public TransferEntity transferEntity = new TransferEntity();
	}

	public GetTransferDetailInvokItemResult getOutput() {
		return (GetTransferDetailInvokItemResult) GetResultObject();
	}

	public GetTransferDetailInvokItem(String turnoverid) {
		String url = APIConfiguration.getBaseUrl()
				+ "Purse/Purse/turnoverDetail?turnoverid=" + turnoverid + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		GetTransferDetailInvokItemResult result = new GetTransferDetailInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			JSONObject data = json.optJSONObject("data");
			if (data == null) {
				return result;
			}
			result.transferEntity = desTransferEntity(data);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return result;
	}

	private TransferEntity desTransferEntity(JSONObject json) {
		TransferEntity mTransferEntity = new TransferEntity();
		mTransferEntity.id = json.optInt("id");
		mTransferEntity.subject = json.optString("subject");
		mTransferEntity.amount = json.optString("amount");
		mTransferEntity.memo = json.optString("memo");
		mTransferEntity.createtime = json.optString("createtime");
		mTransferEntity.nickname = json.optString("nickname");
		mTransferEntity.mobile = json.optString("mobile");
		mTransferEntity.fnickname = json.optString("fnickname");
		mTransferEntity.fmobile = json.optString("fmobile");
		mTransferEntity.leftamount = json.optString("leftamount");
		mTransferEntity.turnoverid = json.optString("turnoverid");
		mTransferEntity.custid = json.optLong("custid");
		mTransferEntity.fcustid = json.optLong("fcustid");
		return mTransferEntity;
	}
}
